package com.example.shw

import android.graphics.drawable.ClipDrawable
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.ImageView
import java.util.*

class OpenImageActivity : AppCompatActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_openimage)
        val imageview = findViewById<ImageView>(R.id.image_01)
        val drawable = imageview.drawable as ClipDrawable

        class MyHandle : Handler(){
            override fun handleMessage(msg: Message) {
                super.handleMessage(msg)
                if (msg.what == 0x1233)
                {
                    Log.d("12345","handle ${drawable.level}")
                    drawable.level = drawable.level + 50
                }
            }
        }
        val handler = MyHandle()
        val timer = Timer()
        timer.schedule(object : TimerTask(){
            override fun run() {
                val msg = Message()
                msg.what = 0x1233
                handler.sendMessage(msg)
                Log.d("12345","timer ")
                if (drawable.level >= 10000){
                    timer.cancel()
                }
            }
        }, 0, 16)
    }
}